************************************************************************************************************************************************
************************ Using Rich Lists to Study the Super-Rich and Top Wealth Inequality: Insights from Switzerland *************************
************************************************************************************************************************************************

clear all
set more off
set scheme s1color  

**Author: Enea Baselgia and Isabel Z. Martinez
**Date: April, 4 2024

***************************************************************************************************************************************************
***** How Rich are the super-rich?
***************************************************************************************************************************************************

** Chapter 5.1: Evolution of Total Wealth at the Top** 
*load data
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear

sort year rank
by year: gen ranknumber =_n
egen top10 = sum(wealth_R) if ranknumber<=10, by(year)
egen top50 = sum(wealth_R) if ranknumber<=50, by(year)
egen  top100 = sum(wealth_R) if ranknumber<=100, by(year)
egen  top150 = sum(wealth_R) if ranknumber<=150, by(year)
egen  top200 = sum(wealth_R) if ranknumber<=200, by(year)

collapse (mean) top10 (mean) top50 (mean) top100 (mean) top150 (mean) top200 (mean) ch_pW_T_R, by(year) 

* restrict analysis to the years after 1995
drop if year < 1995
* replace top200 bc sample is smaller than 200 for these two year
replace top200=. if year==1995 |year==1996

gen top10_i = 100 if year==2000
gen top50_i = 100 if year==2000
gen top100_i = 100 if year==2000
gen top150_i = 100 if year==2000
gen top200_i = 100 if year==2000
gen pW_tot_i = 100 if year==2000

replace top10_i = top10_i[6]/ top10[6] * top10
replace top50_i = top50_i[6]/ top50[6] * top50
replace top100_i = top100_i[6]/ top100[6] * top100
replace top150_i = top150_i[6]/ top150[6] * top150
replace top200_i = top200_i[6]/ top200[6] * top200
replace pW_tot_i = pW_tot_i[6]/ ch_pW_T_R[6] * ch_pW_T_R

label var top10_i "Top 10"
label var top50_i "Top 50"
label var top100_i "Top 100"
label var top150_i "Top 150"
label var top200_i "Top 200"
label var pW_tot_i "Total Private Wealth"

cd "$mypath/output/figures/"

tw  (connect top10_i year if year>=1995, msymb(O) mcolor(gs0) msize() lcolor(gs0) lpattern()) ////
	(connect top100_i year if year>=1995, msymb(D) mcolor(gs7) msize() lcolor(gs7) lpattern()) ////
	(connect top200_i year if year>=1995, msymb(T) mcolor(gs11) msize() lcolor(gs11) lpattern()) ////
	(connect pW_tot_i year if year>=1995, msymb(Sh) mcolor(gs0) msize() lcolor(gs0) lpattern())    ///
	, ytitle("real wealth 2000=100", size()) xtitle("") ///
	ylab(, grid) xlab(1995(5)2020, grid) legend(row(2) size(small)) 
	
	graph export "top_wealth_evolution.pdf", as(pdf) replace
	
	

	
***** Chapter 5.2: Top 0.01% Wealth Shares
clear all
* The do-file do "5_a_estimate_TWS.do" loads the aggregated Swiss tax statistics (raw data; file: tws_2017_restat_updated.xlsx) and performs a pareto-interpolation to contsruct top wealth share and save this top shares (in a speperate dataset)
* Specifically, this updates the top-shares constructed in Reto Foellmi, Isabel Z. Martínez; Volatile Top Income Shares in Switzerland? Reassessing the Evolution between 1981 and 2010. The Review of Economics and Statistics 2017; 99 (5): 793–809. doi: https://doi.org/10.1162/REST_a_00644

cd "$mypath/"
do "5_a_estimate_TWS.do"
cd "$mypath/"
use "2560_BILANZ-SwissRichListDataset_1989-2020_Data_v1.0.dta", clear
merge m:1 year using "TWS_dataset.dta", nogen

drop P10_5 P5_1 P10_1 P1_05 P1_01 P05_01 P01_001 ts90 ts95 ts99 ts995 ts999 ts9999 wea_avg90 wea_avg95 wea_avg99 wea_avg995 wea_avg999 wea_avg9999 top10_within_top1 top1_within_top1 top10_within_top10 alpha beta tu_total wea_total total_pop total_taxunits

drop if year < 1999

*** Number of Tax Units of Top 0.01% 
preserve
gen TU_P9999 = tot_taxunits * 0.0001
collapse TU_P9999, by(year)
gen TU_P9999_round = int(TU_P9999)
tab TU_P9999_round 
restore

/*
//year	TU_P9999
//1999	400
//2000	403
//2001	409
//2002	414
//2003	418
//2004	423
//2005	428
//2006	434
//2007	442
//2008	452
//2009	459
//2010	467
//2011	475
//2012	481
//2013	489
//2014	497
//2015	504
//2016	510
//2017	515
//2018	520
//2019	525
//2020	531
*/

* FAMILY SPLIT 3

preserve

gen split=1			
sum wealth_mean if fam==1
* 2,530 obs. are families in the panel from 2000-2020
replace split=3 if fam==1				
expand split, gen(indic_original)		
sort year id_pers			
			
replace wealth_mean = wealth_mean/3 if fam==1  			
*--> (7,590 real changes made) this is correct as 2530*3=7590

gsort year -wealth_mean		
by year: gen ranknumber =_n			
by year: summarize ranknumber		

drop if year==1999	& ranknumber>400
drop if year==2000	& ranknumber>403
drop if year==2001	& ranknumber>409
drop if year==2002	& ranknumber>414
drop if year==2003	& ranknumber>418
drop if year==2004	& ranknumber>423
drop if year==2005	& ranknumber>428
drop if year==2006	& ranknumber>434
drop if year==2007	& ranknumber>442
drop if year==2008	& ranknumber>452
drop if year==2009	& ranknumber>459
drop if year==2010	& ranknumber>467
drop if year==2011	& ranknumber>475
drop if year==2012	& ranknumber>481
drop if year==2013	& ranknumber>489
drop if year==2014	& ranknumber>497
drop if year==2015	& ranknumber>504
drop if year==2016	& ranknumber>510
drop if year==2017	& ranknumber>515
drop if year==2018	& ranknumber>520
drop if year==2019	& ranknumber>525
drop if year==2020	& ranknumber>531

sort year ranknumber			

collapse (count) obs_3S_01per=id_pers (mean) avgW_3S_01per=wealth_mean (sum) totW_3S_01per=wealth_mean, by(year) 

tempfile fam_split_3
save "`fam_split_3'"
					
restore
	

* FAMILY SPLIT 5
	
preserve

gen split=1			
sum wealth_mean if fam==1
* 2,530 obs. are families in the panel from 2000-2020
replace split=5 if fam==1				
expand split, gen(indic_original)		
sort year id_pers			
			
replace wealth_mean = wealth_mean/5 if fam==1  			
** --> (12,650 real changes made) this is correct as 2530*5=12650	

gsort year -wealth_mean			
by year: gen ranknumber =_n			
			
by year: summarize ranknumber

drop if year==1999	& ranknumber>400
drop if year==2000	& ranknumber>403
drop if year==2001	& ranknumber>409
drop if year==2002	& ranknumber>414
drop if year==2003	& ranknumber>418
drop if year==2004	& ranknumber>423
drop if year==2005	& ranknumber>428
drop if year==2006	& ranknumber>434
drop if year==2007	& ranknumber>442
drop if year==2008	& ranknumber>452
drop if year==2009	& ranknumber>459
drop if year==2010	& ranknumber>467
drop if year==2011	& ranknumber>475
drop if year==2012	& ranknumber>481
drop if year==2013	& ranknumber>489
drop if year==2014	& ranknumber>497
drop if year==2015	& ranknumber>504
drop if year==2016	& ranknumber>510
drop if year==2017	& ranknumber>515
drop if year==2018	& ranknumber>520
drop if year==2019	& ranknumber>525
drop if year==2020	& ranknumber>531

sort year ranknumber			

collapse (count) obs_5S_01per=id_pers (mean) avgW_5S_01per=wealth_mean (sum) totW_5S_01per=wealth_mean, by(year) 


tempfile fam_split_5
save "`fam_split_5'"
					
restore
							

							
* FAMILY SPLIT 7									
preserve		

gen split=1			
sum wealth_mean if fam==1
* 2,530 obs. are families in the panel from 2000-2020
replace split=7 if fam==1				
expand split, gen(indic_original)		
sort year id_pers			
			
replace wealth_mean = wealth_mean/7 if fam==1  			
* --> (17,710 real changes made) this is correct as 2530*7=17710	
	
gsort year -wealth_mean			
by year: gen ranknumber =_n			
			
by year: summarize ranknumber		
			
drop if year==1999	& ranknumber>400
drop if year==2000	& ranknumber>403
drop if year==2001	& ranknumber>409
drop if year==2002	& ranknumber>414
drop if year==2003	& ranknumber>418
drop if year==2004	& ranknumber>423
drop if year==2005	& ranknumber>428
drop if year==2006	& ranknumber>434
drop if year==2007	& ranknumber>442
drop if year==2008	& ranknumber>452
drop if year==2009	& ranknumber>459
drop if year==2010	& ranknumber>467
drop if year==2011	& ranknumber>475
drop if year==2012	& ranknumber>481
drop if year==2013	& ranknumber>489
drop if year==2014	& ranknumber>497
drop if year==2015	& ranknumber>504
drop if year==2016	& ranknumber>510
drop if year==2017	& ranknumber>515
drop if year==2018	& ranknumber>520
drop if year==2019	& ranknumber>525
drop if year==2020	& ranknumber>531

sort year ranknumber			


collapse (count) obs_7S_01per=id_pers (mean) avgW_7S_01per=wealth_mean (sum) totW_7S_01per=wealth_mean, by(year) 

tempfile fam_split_7
save "`fam_split_7'"
					
restore
	
keep year ch_pW_T P9999   
collapse (mean) ch_pW_T (mean) P9999, by(year) 

merge 1:1 year using "`fam_split_3'", nogenerate		
merge 1:1 year using "`fam_split_5'", nogenerate		
merge 1:1 year using "`fam_split_7'", nogenerate		
				
				
drop obs_3S_01per obs_5S_01per avgW_3S_01per avgW_5S_01per avgW_7S_01per 	
rename obs_7S_01per	TU_P9999
			
foreach var of varlist totW_3S_01per totW_5S_01per totW_7S_01per{
gen sh_`var' = `var' / ch_pW_T
}		

drop totW_3S_01per totW_5S_01per totW_7S_01per

rename sh_totW_3S_01per P9999_S3
rename sh_totW_5S_01per P9999_S5
rename sh_totW_7S_01per P9999_S7

label var P9999_S3 "rich-list (split by 3)" 
label var P9999_S5 "rich-list (split by 5)" 
label var P9999_S7 "rich-list (split by 7)" 

label var P9999 "taxable wealth" 
 
*figures
cd "$mypath/output/figures/"
	
tw  (connect P9999_S5 year if year >=2000, msymb(O) mcolor(gs0)  msize() lcolor(gs0) lpattern())  ///
	(connect P9999 year if year >=2000, msymb(D) mcolor(gs7) msize() lcolor(gs7) lpattern() )    ///
	, ytitle("top 0.01% wealth share", size(normalsize)) xtitle("") ///
	ylab(0 "" 0.05 "5%" 0.1 "10%" 0.15 "15%" 0.2 "20%", labsize() grid gmax gmin) xlab(2000(5)2020, grid gmax gmin) legend(row(1) size(medsmall))	
	
graph export "tws.pdf", as(pdf) replace
	
		
gen helpline=0.21
label var helpline "tax units top 0.01%"
	
tw  (connect P9999_S3 year if year >=2000, msymb(Dh) mcolor(gs7) msize() lcolor(gs7) lpattern(shortdash))    ///
	(connect P9999_S5 year if year >=2000, msymb(O) mcolor(gs0)  msize() lcolor(gs0) lpattern())  ///
	(connect P9999_S7 year if year >=2000, msymb(Sh) mcolor(gs7)  msize() lcolor(gs7) lpattern(shortdash)) ///
	(connect helpline year if year >=2000, msymb(T) mcolor(black)  msize() lcolor(black) lpattern(longdash) mlabel(TU_P9999) mlabsize(vsmall) mlabcolor(black) mlabposition(6))  ///
	, ytitle("top 0.01% wealth share", size(normalsize)) xtitle("") ///
	 ylab(0.12 "12%" 0.14 "14%" 0.16 "16%" 0.18 "18%" 0.20 "20%" 0.22 "22%", labsize(normalsize) grid gmax gmin) xlab(2000(5)2020, labsize(normalsize) grid gmax gmin) legend(row(3) size(normalsize))	
	
graph export "tws_robustness.pdf", as(pdf) replace
	
